﻿@model JewererBasic.COMPONENT_ORDER_DETAIL
<h2>Details</h2>
@using (Html.BeginForm())
{
    <fieldset>
        @if (Model != null)
        {
            @Html.HiddenFor(m => m.Component_Id)
            @Html.HiddenFor(m => m.Component_Order_Id)
            @Html.HiddenFor(m => m.Finish, new { @id = "finish" })
            @Html.HiddenFor(m => m.Id)              

            <a href="/ComponentOrder/Index">
                <input type="button" value="BACK" />
            </a>
            
            <fieldset>
                <legend>Information</legend>
                <table class="table head">
                    <tr>
                        <th style="width: 200px; text-align: center">Bag Id</th>
                        <th style="width: 200px; text-align: center">MC</th>
                        <th style="width: 200px; text-align: center">Component Id</th>
                        <th style="width: 200px; text-align: center">Worker Id</th>
                        @if (Model.Finish == -1)
                        {
                            @Html.HiddenFor(m => m.Return_Weight)  
                            @Html.HiddenFor(m => m.Dust)  
                        }
                        else if (Model.Finish == 1)// has finished
                        {
                            <th style="width: 200px; text-align: center">Return Weight</th>
                            <th style="width: 200px; text-align: center">Dust Weight</th>                                                 
                        }
                        else if (Model.Finish == 0)
                        {// started
                            <th style="width: 200px; text-align: center">Return Weight</th>
                            <th style="width: 200px; text-align: center">Dust Weight</th>                            
                        }
                    </tr>
                    <tr>
                        <td>@Html.DisplayFor(model => model.Id)</td>
                        <td>@Html.DisplayFor(model => model.COMPONENT_ORDER.MC)</td>
                        <td>@Html.DisplayFor(model => model.Component_Id)</td>
                        <td>
                            @if (Model.Finish == -1)
                            {
                                @Html.DropDownListFor(m => m.Worker_Id, new SelectList(ViewBag.Workers, "Id", "Staff_Id"), new { id = "ddlStaffId" })
                            }
                            else
                            {
                                @Html.DisplayFor(model => model.Worker_Id)

                                // save data
                                @Html.HiddenFor(m => m.Worker_Id)
                            }
                        </td>

                        @if (Model.Finish == -1)
                        {
                            @Html.HiddenFor(m => m.Return_Weight)  
                            @Html.HiddenFor(m => m.Dust)  
                        }
                        else if (Model.Finish == 1)// has finished
                        {
                            <td>@Html.DisplayFor(model => model.Return_Weight)</td>                            
                            <td>@Html.DisplayFor(model => model.Dust)</td>
                            @Html.HiddenFor(m => m.Return_Weight)
                            @Html.HiddenFor(m => m.Dust)
                        }
                        else if (Model.Finish == 0)
                        {// started
                            <td>@Html.TextBoxFor(model => model.Return_Weight, new { @required = "required", @id = "txtReturnWeight" })
                                @Html.ValidationMessageFor(m => m.Return_Weight)
                            </td>
                            <td>
                                @Html.TextBoxFor(model => model.Dust, new { @required = "required", @id = "txtDustWeight" })
                                @Html.ValidationMessageFor(m => m.Dust)
                            </td>
                        }
                    </tr>

                </table>
            </fieldset>
            <fieldset>
                @if (Model.COMPONENT_ORDER_COM_MOLECULE_EXPORT != null)
                {
                    <table>
                        <tr>
                            <td>
                                @if (Model.Finish == -1)
                                {
                                    <table class="table head">
                                        <tr>
                                            <th style="width: 200px; text-align: center">Component Id</th>
                                            <th style="width: 200px; text-align: center">Percentage</th>
                                            <th style="width: 200px; text-align: center">Weight</th>
                                        </tr>
                                        @Html.EditorFor(m => m.COMPONENT_ORDER_COM_MOLECULE_EXPORT)
                                    </table>
                                }
                                else
                                {
                                    <table class="table head">
                                        <tr>
                                            <th style="width: 200px; text-align: center">Component Id</th>
                                            <th style="width: 200px; text-align: center">Percentage</th>
                                            <th style="width: 200px; text-align: center">Weight</th>
                                        </tr>
                                        @for (int i = 0; i < Model.COMPONENT_ORDER_COM_MOLECULE_EXPORT.Count(); i++)
                                        {                                
                                            <tr>
                                                <td style="text-align: center">
                                                    @Html.DisplayFor(m => m.COMPONENT_ORDER_COM_MOLECULE_EXPORT.ElementAt(i).Com_Slaver_Id)
                                                </td>
                                                <td style="text-align: center">
                                                    @Html.DisplayFor(m => m.COMPONENT_ORDER_COM_MOLECULE_EXPORT.ElementAt(i).Percentage)
                                                </td>
                                                <td style="text-align: center">
                                                    @Html.DisplayFor(m => m.COMPONENT_ORDER_COM_MOLECULE_EXPORT.ElementAt(i).Export_Weight)
                                                </td>
                                            </tr>        
                                        }
                                    </table>                
                                }
                            </td>
                        </tr>
                    </table>
                }
            </fieldset>                
            <p>
                @if (Model.Finish == -1)
                {
                    <input type="submit" value="Save" name="submit" />
                    <input type="submit" value="Export" name="submit" />
                }
                else if (Model.Finish == 0)
                {
                    <input type="submit" value="Finish" name="submit" />
                }
            </p>    
        }
    </fieldset>
}

@section Scripts{

    <script type="text/javascript">
        //$(document).ready(function () {
        //    $("form").submit(function (evt) {
        //        var finish = $('#finish').val();
        //        if(finish=0){
        //            var return_weight = $('#txtReturnWeight').val();
        //            if (!return_weight) {
        //                evt.preventDefault();
        //            }else if(return_weight<=0){
        //                evt.preventDefault();
        //            }
        //        }

        //    });
        //});
    </script>
}